<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> 将 Array 类型变成 Object 类型</title>
</head>
<body>
    <script>
      var num=[1,24,512,56,112,0,22]
      var obj={}
      //遍历数组
      for(var i=0;i<num.length;i++){
        //将数组的元素赋值给空对象obj
        obj[i]=num[i]
      }
      //通过length属性获得数组的长度赋值给对象obj
      obj.length=num.length
      console.log(obj)
    </script>
</body>
</html>